package dp.gr03.payroll.payrollDatabase;

import java.util.ArrayList;
import java.util.HashMap;

import dp.gr03.payroll.payrollDomain.Employee;

public class PayrollDatabase
{

    private static PayrollDatabase instance;
    protected HashMap<Integer, Employee> employees;
    protected HashMap<Integer, Integer> unionMembers;

    private PayrollDatabase()
    {
        employees = new HashMap<Integer, Employee>();
        unionMembers = new HashMap<Integer, Integer>();
    }

    public static PayrollDatabase getInstance()
    {
        if (instance == null)
        {
            instance = new PayrollDatabase();
        }
        return instance;
    }

    public Employee getEmployee(int employeeId)
    {
        return employees.get(employeeId);
    }
    
    public boolean employeeExists(int employeeId){
        Employee e = getEmployee(employeeId);
        if(e == null){
            return false;
        }
        else{
            return true;
        }
    }

    public void getAllEmployeeIds(ArrayList<Integer> empIds)
    {
        empIds.addAll(employees.keySet());
    }

    public void addEmployee(Employee employeeToAdd)
    {
        employees.put(employeeToAdd.getId(), employeeToAdd);
    }

    public void deleteEmployee(int employeeId)
    {
        employees.remove(employeeId);
    }

    public void addUnionMember(int memberId, Employee e)
    {
        unionMembers.put(memberId, e.getId());
    }

    public Employee getUnionMember(int memberId)
    {
        return getEmployee(unionMembers.get(memberId));
    }

    public void deleteUnionMember(int memberId)
    {
        unionMembers.remove(memberId);
    }

    public void clear()
    {
        unionMembers.clear();
        employees.clear();
        
    }
}
